<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://www.springframework.org/tags/form"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:include page="../../set.jsp" />
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title>用户中心</title>
<jsp:include page="../../cite.jsp" />
<link rel="stylesheet" href="${_path}/theme/theme-menu.css">
<script src="${_path}/lib/bootbox-4.4.0/bootbox.min.js"></script>
<style>
.body {
	padding-top: 40px;
}

.body .panel>.panel-body {
	padding-top: 30px;
}

.body .alert {
	margin: 10px 10px 0 10px;
}
</style>
</head>
<body>
	<jsp:include page="../../header.jsp" />
	<jsp:include page="./user-menu.jsp?active=pwd" />
	<div class="body">
		<div class="panel panel-default">
			<c:if test="${succ == true}">
				<div class="alert alert-success alert-dismissible fade in" id="alert">修改成功</div>
			</c:if>
			<div class="panel-body">
				<f:form class="form-horizontal" method="post" modelAttribute="userPwdParam" id="form">
					<div class="form-group form-group-sm row">
						<label class="col-sm-2 control-label" for="password">
							<span class="text-danger">*</span>
							原密码
						</label>
						<div class="col-sm-8">
							<f:input path="pwd" type="password" class="form-control" placeholder="原密码" required="true" autofocus="true" />
							<f:errors path="pwd" class="text-danger" />
						</div>
					</div>
					<hr>
					<div class="form-group form-group-sm row">
						<label class="col-sm-2 control-label" for="npwd">
							<span class="text-danger">*</span>
							新密码
						</label>
						<div class="col-sm-8">
							<f:input path="npwd" type="password" class="form-control" placeholder="新密码" required="true" />
							<f:errors path="npwd" class="text-danger" />
						</div>
					</div>
					<div class="form-group form-group-sm row">
						<label class="col-sm-2 control-label" for="rnpwd">
							<span class="text-danger">*</span>
							重复密码
						</label>
						<div class="col-sm-8">
							<input type="password" class="form-control" name="rnpwd" placeholder="重复新密码" required>
						</div>
					</div>
					<hr>
					<div class="form-group row">
						<div class="col-sm-offset-2 col-sm-8">
							<a href="./" class="btn btn-link btn-sm">清 空</a>
							<button type="submit" class="btn btn-primary btn-sm" data-loading-text="提交中...">修 改</button>
							<a href="javascript:;" class="btn btn-link btn-sm pull-right" id="repwd">忘记密码？</a>
							<f:errors class="text-danger" />
						</div>
					</div>
				</f:form>
			</div>
		</div>
	</div>
	<script>
		$(function() {
			bootbox.setLocale('zh_CN');
			$('#form').submit(function() {
				if ($('#form input[name=npwd]').val() != $('#form input[name=rnpwd]').val()) {
					bootbox.alert('两次输入的密码不一致');
					return false;
				}
				$('#form button[data-loading-text]').button('loading');
				return true;
			});
			$('#repwd').bind('click', function() {
				bootbox.confirm('是否确认重置密码？', function(c) {
					if (c)
						$.ajax({
							url : './repwd/',
							type : 'post',
							dataType : 'json',
							success : function(result) {
								if (result.succ == 0)
									bootbox.alert('重置成功，密码已发送至您的邮箱');
								else
									bootbox.alert(result.message);
							},
							error : function() {
								bootbox.alert('网络连接失败');
								console.log('重置用户密码失败');
							}
						});
				});
			});
			if ($('#alert').length != 0)
				setTimeout(function() {
					$('#alert').alert('close');
				}, 1500);
		});
	</script>
</body>
</html>